package cn.wolfcode.crm.util;

import cn.wolfcode.crm.domain.Employee;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {

    public static HttpSession getSession(){
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return attributes.getRequest().getSession();
    }
    // 往 session 中存入对象
    public static void setCurrentEmployee(Employee employee){
        getSession().setAttribute("EMPLOYEE_IN_SESSION",employee);
    }

    // 从 session 中获取对象
    public static Employee getCurrentUser() {
        return (Employee) getSession().getAttribute("EMPLOYEE_IN_SESSION");
    }

    // 往 session 中存入权限信息(集合)
    public static void setExpression(List<String> expressions){
        getSession().setAttribute("EXPRESS_IN_SESSION",expressions);
    }
    // 从 session 中获取权限信息(集合)

    public static List<String> getExpression(){
        return (List<String>) getSession().getAttribute("EXPRESS_IN_SESSION");
    }
}
